package com.romotc.qqrobot.bean;

import java.sql.Timestamp;

import org.json.JSONException;

import com.romotc.oschina.bean.POJO;
import com.romotc.qqrobot.webqq.WebQQConstant;
import com.romotc.scache.RequestSpy;

/**
 * Qq号码A 获取的QQ号码B的用户资料
 * 获取自己：
 * http://s.web2.qq.com/api/get_friend_info2?tuin=1586030808&verifysession=&code=&vfwebqq=d8a57fa432785413ba2bc8f323816b9b7b9b52a8e2af59e54646718eca64e2725002e79d94ed3fb4&t=1325628530631
 * {"retcode":0,"result":{"face":540,"birthday":{"month":3,"year":2011,"day":17},
 * 		"occupation":"","phone":"","allow":0,"college":"","reg_time":0,"uin":1586030808,
 * 		"constel":2,"blood":0,"homepage":"","stat":10,"vip_info":0,"country":"中国","city":"济南","personal":"","nick":"opendev","shengxiao":4,"email":"","client_type":41,"province":"山东","gender":"male","mobile":""}}
   
   http://s.web2.qq.com/api/get_friend_info2?tuin=4161888596&verifysession=&code=&vfwebqq=d8a57fa432785413ba2bc8f323816b9b7b9b52a8e2af59e54646718eca64e2725002e79d94ed3fb4&t=1325628547349
   获取到的别人：{"retcode":0,"result":{"face":0,"birthday":{"month":0,"year":0,"day":0},
   		"occupation":"","phone":"-","allow":0,"college":"shuchang","reg_time":0,"uin":4161888596,
   		"constel":0,"blood":3,"homepage":"http://www.Romotc.com","stat":20,"vip_info":0,"country":"","city":"","personal":"-","nick":"Romotc","shengxiao":0,"email":"romotc@gmail.com","province":"","gender":"unknown","mobile":"133********"}}
 * @author Administrator
 *
 */
public class QQInfoFromQQLogedin extends POJO{

//	private int allow;
//	private String college;
//	private int reg_time;
//	private int uin;
//	private int constel;
//	private int blood;
//	private String homepage;
//	private int stat;
//	private int vip_info;
//	private String country;
//	private String city;
	/**
	 * QQ号码A 获取资料动作的发起者
	 */
	private String fromQq;
	
	/**
	 * QQ号码B对应QQ号码A本次登录的uin
	 */
	private int tuin;
	
	/**
	 * 所获取到的信息
	 */
	private String info;
	
	private long reqId;
	
	/**
	 * 此信息的获取时间
	 */
	private Timestamp infoTime = new Timestamp(System.currentTimeMillis());
//	private int face;
//	private int birthday_month;
//	private int birthday_year;
//	private int birthday_day;
//	private String occupation;
//	private String phone;
	/**
	 * 
	 * @param rqSpy
	 * @return
	 */
	public static QQInfoFromQQLogedin buildQQInfo(RequestSpy rqSpy) {
		// TODO Auto-generated method stub
		
		QQInfoFromQQLogedin qqInfo = new QQInfoFromQQLogedin();
		qqInfo.setReqId(rqSpy.getReqSN());
		
		String fromQq;
		try {
			fromQq = rqSpy.getReqCookiesJson().getString(WebQQConstant.Cookie_ptui_loginuin);
			qqInfo.setFromQq(fromQq);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			qqInfo.setFromQq(String.valueOf(-998));
		}
		
		
		int tuin;
		try {
			tuin = rqSpy.getReqInfoJson().getInt(WebQQConstant.REQUEST_PARAMS_Get_friend_info2_Tuin);
			qqInfo.setTuin(tuin);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			qqInfo.setTuin(-999);
		}
		
		qqInfo.setInfo(rqSpy.getResBody());
		
		qqInfo.Save();
		
		return qqInfo;
	}
	public String getFromQq() {
		return fromQq;
	}
	public void setFromQq(String fromQq) {
		this.fromQq = fromQq;
	}
	public int getTuin() {
		return tuin;
	}
	public void setTuin(int tuin) {
		this.tuin = tuin;
	}
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}
	public long getReqId() {
		return reqId;
	}
	public void setReqId(long reqId) {
		this.reqId = reqId;
	}
	public Timestamp getInfoTime() {
		return infoTime;
	}
	public void setInfoTime(Timestamp infoTime) {
		this.infoTime = infoTime;
	}
	
	public static void main(String args[]) {
		QQInfoFromQQLogedin qqInfo = new QQInfoFromQQLogedin();
		System.out.println(qqInfo.TableName());
		
		qqInfo.setFromQq("1586030808");
		qqInfo.setInfo("{\"retcode\":0,\"result\":{\"face\":540,\"birthday\":{\"month\":3,\"year\":2011,\"day\":17},\"occupation\":\"\",\"phone\":\"\",\"allow\":0,\"college\":\"\",\"reg_time\":0,\"uin\":1586030808,\"constel\":2,\"blood\":0,\"homepage\":\"\",\"stat\":10,\"vip_info\":0,\"country\":\"中国\",\"city\":\"济南\",\"personal\":\"\",\"nick\":\"opendev\",\"shengxiao\":4,\"email\":\"\",\"client_type\":41,\"province\":\"山东\",\"gender\":\"male\",\"mobile\":\"\"}}");
		
		qqInfo.setTuin(1586030808);
		
		qqInfo.Save();
	}

}
